<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <script src="../js/jquery.min.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=1j6EsGUMVRcrUm1fq7ba7yHISWyqvwhI"></script>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>首页<small>公司分布图</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <template>
                <el-tabs v-model="activeName">
                    <el-tab-pane name="first">
                        <span slot="label"><i>&nbsp;&nbsp;&nbsp;&nbsp;</i>分布图</span>
                        <!--百度地图容器-->
                        <div style="width:100%;height:550px;border:#ccc solid 1px;" id="allmap"></div>
                    </el-tab-pane>
                    <el-tab-pane label="详细信息" name="second">
                        <div class="app-container">
                            <div class="box">
                                <div class="filter-container">
                                    <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                                    <el-button @click="findPage()" class="dalfBut">查询</el-button>
                                    <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                                </div>
                                <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                                    <el-table-column type="index" align="center" label="序号"></el-table-column>
                                    <el-table-column prop="address" label="公司地址" align="center"></el-table-column>
                                    <el-table-column prop="longitude" label="所在经度" align="center"></el-table-column>
                                    <el-table-column prop="latitude" label="所在维度" align="center"></el-table-column>
                                    <el-table-column label="操作" align="center">
                                        <template slot-scope="scope">
                                            <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                                        </template>
                                    </el-table-column>
                                </el-table>
                                <div class="pagination-container">
                                    <el-pagination
                                            class="pagiantion"
                                            @current-change="handleCurrentChange"
                                            :current-page="pagination.currentPage"
                                            :page-size="pagination.pageSize"
                                            layout="total, prev, pager, next, jumper"
                                            :total="pagination.total">
                                    </el-pagination>
                                </div>
                                <!-- 新增标签弹层 -->
                                <div class="add-form">
                                    <el-dialog title="新增地址" :visible.sync="dialogFormVisible" v-if="dialogFormVisible">
                                        <el-form ref="dataAddForm" :model="formData" label-position="right" label-width="100px">
                                            <el-row  >
                                                <iframe frameborder="0" src='minbaidumap.html' width="100%" height="500px" ></iframe>
                                            </el-row>
                                        </el-form>
                                    </el-dialog>
                                </div>
                            </div>
                        </div>
                    </el-tab-pane>
                </el-tabs>
            </template>
        </div>
    </body>
    <script>

        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:10,//每页显示的记录数
					  total:0,//总记录数
					  queryString:null,//查询条件

				},
				dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据      30.878774,104.021293
                dialogFormVisible: false,//增加表单是否可见
            },
            mounted() {
                this.findPage();

            },
                //钩子函数，VUE对象初始化完成后自动执行
            created() {

                // this.intoMap();
            },
            methods: {
                //添加
                handleAdd () {
                },
                //分页查询
                async findPage() {
                    var result = {};
                    var param={
                        currentPage: this.pagination.currentPage,//当前页码
                        pageSize: this.pagination.pageSize,//每页显示的记录数
                        queryString: this.pagination.queryString//查询条件
                    };
                    //发送请求 基于VUE双向绑定
                    await axios.post("/address/findPage.do", param).then((res) => {
                         result = res.data.rows;
                        this.pagination.total = res.data.total;
                    });
                    this.dataList = result;
                    this.intoMap();
                },
                // 重置表单
                resetForm(formName) {
                },
                // 弹出添加窗口
                handleCreate() {
                    this.dialogFormVisible = true;
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {
                    //弹出确认框
                    this.$confirm('你确定要删除当前地址吗？','提示',{
                         confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        //发送ajax请求，将id提交到Controller
                        axios.get("/address/deleteAddress.do?id=" + row.id).then((res) => {
                            if(res.data.flag){
                                this.$message({
                                    type:'success',
                                    message:res.data.message,
                                });
                                this.findPage();
                            }else{
                                //执行失败
                                this.$message.error(res.data.message);
                            }
                        }).catch((r) => {
                            this.showMessage(r);
                        });
                    }).catch(() => {
                        this.$message("已取消");
                    });
                },

                addClickHandler(content,marker,opts){
                    marker.addEventListener("click",function(e){
                        var p = e.target;
                        var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
                        var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象
                        map.openInfoWindow(infoWindow,point); //开启信息窗口
                    });
                },

                intoMap() {

                    // 百度地图API功能
                    var map = new BMap.Map("allmap");    // 创建Map实例
                    map.centerAndZoom(new BMap.Point(104.120, 30.675), 11);  // 初始化地图,设置中心点坐标和地图级别
                    //添加地图类型控件
                    map.addControl(new BMap.MapTypeControl({
                        mapTypes:[
                            BMAP_NORMAL_MAP,
                            BMAP_HYBRID_MAP
                        ]}));
                    map.setCurrentCity("成都");          // 设置地图显示的城市 此项是必须设置的
                    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
                    window.map = map;
                    console.log(close);
                    var addressArr = this.dataList;
                    var opts = {
                        width : 250,     // 信息窗口宽度
                        height: 10,     // 信息窗口高度
                    };
                    for(var i=0;i<addressArr.length;i++){
                        var marker = new BMap.Marker(new BMap.Point(addressArr[i].longitude,addressArr[i].latitude));  // 创建标注
                        var content = addressArr[i].address;
                        map.addOverlay(marker);               // 将标注添加到地图中
                        this.addClickHandler(content,marker,opts);
                    }
                }
            }
        });
    </script>
</html>

